﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using RooHui.Infrastructure.Entities.EFContext;
using RooHui.Infrastructure.Entities.Repository;
using RooHui.Infrastructure.Entities.Enum;

namespace RooHui.Infrastructure.Entities.Entity
{
    public class Information : IAccessible<P_Information, Information>, ILogicEntity<P_Information, Information>
    {
        public int ID { get; set; }
        public string Title { get; set; }
        public string Content { get; set; }
        public string InfoFrom { get; set; }
        public InfoType InfoType { get; set; }
        public ItemStatus Status { get; set; }
        public string CreateUser { get; set; }
        public DateTime CreateTime { get; set; }

        protected override void Covariant(P_Information model)
        {
            if (model != null)
            {
                this.ID = model.ID;
                this.InfoType = (InfoType)model.InfoType;
                this.InfoFrom = model.InfoFrom;
                this.Content = model.Content;
                this.Title = model.Title;
                this.Status = (ItemStatus)model.Status;
                this.CreateTime = model.CreateTime;
                this.CreateUser = model.CreateUser;
            }
        }

        protected override P_Information Inverter(Information model)
        {
            if (model != null)
            {
                return new P_Information()
                {
                    ID = model.ID,
                    Content = model.Content,
                    InfoFrom = model.InfoFrom,
                    InfoType = (int)model.InfoType,
                    Title = model.Title,
                    Status = (int)model.Status,
                    CreateTime = model.CreateTime,
                    CreateUser = model.CreateUser
                };
            }
            return null;
        }

        public Information Set(P_Information dbModel)
        {
            Covariant(dbModel);
            return this;
        }
    }
}
